//
//  SettingsPopover.m
//  xKey Interface
//
//  Created by Guillaume SOURDRILLE on 26/03/12.
//  Copyright (c) 2012 Edenyorke. All rights reserved.
//

#import "SettingsPopover.h"

@implementation SettingsPopover
@synthesize bannerChoice;
@synthesize ipTextInput,messageUtils,popoverController,gamerTagInput;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{

    //To have a background
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    [self.view addSubview:tv];
    [self.view sendSubviewToBack:tv];
    
    self.contentSizeForViewInPopover=CGSizeMake(320.0,320.0);
    [super viewDidLoad];
    messageUtils =  [[MessageUtils alloc] init];
    [ipTextInput setText:ipXkey];
    
    banner = [messageUtils getValue:@"banner"];
    if ([banner isEqualToString:@"ON"]){
        [bannerChoice setOn:TRUE];
    }else{
        [bannerChoice setOn:FALSE];
    }
    NSString *gamerTagString = [messageUtils getValue:@"gamertag"];
    if (gamerTagString == nil || [gamerTagString isEqualToString:@""]){
        [gamerTagInput setText:@""];
    }else{
        [gamerTagInput setText:gamerTagString];
        
    }

    
    saveButton.title = NSLocalizedString(@"settings.popover.save.button", @"");
    ipLabel.text = NSLocalizedString(@"settings.popover.ip.label", @"");
    bannerLabel.text = NSLocalizedString(@"settings.popover.banner.label", @"");
    gamerTagLabel.text = NSLocalizedString(@"settings.popover.gamertag.label", @"");
    self.navigationItem.title = NSLocalizedString(@"settings.popover.title", @"");

}

- (void)viewDidUnload
{
    [self setIpTextInput:nil];
    [self setBannerChoice:nil];
  
    saveButton = nil;
    navigationItem = nil;
    ipLabel = nil;
    bannerLabel = nil;
    [self setGamerTagInput:nil];
    gamerTagLabel = nil;
    [super viewDidUnload];
    messageUtils = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
	return YES;
}


- (IBAction)processRetour {
       [popoverController dismissPopoverAnimated:YES]; 
     
}


- (id)initWithParam:(NSString *)param
{
    self = [super init];
    if (self) {
        ipXkey=param;
    }
    
    
    return self;
}


- (IBAction)processSave {
    
    [messageUtils setValue:@"ipxkey" value:[ipTextInput text]];
    [messageUtils setValue:@"gamertag" value:[gamerTagInput text]];
    if (bannerChoice.on){
        [messageUtils setValue:@"banner" value:@"ON"];
    }else{
        [messageUtils setValue:@"banner" value:@"OFF"];
    }

    

    
}


       

@end
